<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/fragment::top">

</head>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <div th:replace="common/fragment::leftmenu"></div>
        <!--End 左侧导航-->

        <!--头部信息-->
        <div th:replace="common/fragment::header"></div>
        <!--End 头部信息-->

        <!--页面主要内容-->
        <main class="lyear-layout-content">

            <div class="container-fluid">

                <div >
                    <form action="#!" class="horizontal " id="edit-form" method="post">

                        <!--商品名-->
                        <div class="form-group col-md-10 ">
                            <label class="col-md-2 control-label" for="goodname" style="text-align: center;line-height: 36px">名称</label>
                            <div class="col-md-8">
                                <input class="form-control" id="goodname" name="goodname"
                                       placeholder="商品名" type="text" th:value="${good.name}">
                                <input id="id" hidden="hidden" th:value="${good.id}"></input>
                            </div>
                        </div>
                        <!--商品规格-->
                        <div class="form-group col-md-10 ">
                            <label class="col-md-2 control-label" for="spec" style="text-align: center;line-height: 36px">商品规格</label>
                            <div class="col-md-8">
                                <input class="form-control" id="spec" name="spec"
                                       placeholder="商品规格" type="text" th:value="${good.spec}">
                            </div>
                        </div>
                        <!--包装-->
                        <!--                                    <div class="form-group col-md-10 ">-->
                        <!--                                        <label class="col-md-2 control-label" for="pk" style="text-align: center;line-height: 36px">包装</label>-->
                        <!--                                        <div class="col-md-8">-->
                        <!--                                            <input class="form-control" id="pk" name="pk"-->
                        <!--                                                   placeholder="包装" type="text">-->
                        <!--                                        </div>-->
                        <!--                                    </div>-->
                        <!--计量单位-->
                        <

                        <div class="form-group col-md-10 ">
                            <label class="col-md-2 control-label" for="unit" style="text-align: center;line-height: 36px">计量单位</label>
                            <div class="col-md-8">
                                <select class="form-control" id="unit" name="unit" size="1"  th:value="${good.unit}">
                                    <option th:each="v:${unitvalue}"  th:value="${v}" th:text="${unitname[v]}">请选择</option>

                                </select>
                            </div>
                        </div>
                        <!--商品价格-->
                        <!--                                    <div class="form-group col-md-10 ">-->
                        <!--                                        <label class="col-md-2 control-label" for="price" style="text-align: center;line-height: 36px">商品价格</label>-->
                        <!--                                        <div class="col-md-8">-->
                        <!--                                            <input class="form-control" id="price" name="price"-->
                        <!--                                                   placeholder="商品价格" type="text">-->
                        <!--                                        </div>-->
                        <!--                                    </div>-->

                        <!--商品状态-->
                        <div class="input-group col-md-10">
                            <label class="col-md-2 control-label" style="text-align: center;line-height: 36px">状态</label>
                            <<div class="col-md-8">
                            <label class="radio-inline" for="good-inline-radio1">
                                <input id="good-inline-radio1" name="goodstatus" type="radio"
                                       value="1" th:checked="${good.getStatus()}==1">
                                启用
                            </label>
                            <label class="radio-inline" for="good-inline-radio2">
                                <input id="good-inline-radio2" name="goodstatus" type="radio"
                                       value="-1" th:checked="${good.getStatus()}==-1">
                                禁用
                            </label>
                        </div>
                        </div>
                        <!--商品注释-->
                        <div class="form-group col-md-10 ">
                            <label class="col-md-2 control-label" for="comment" style="text-align: center;line-height: 36px">备注</label>
                            <div class="col-md-8">
                                <input class="form-control" id="comment" name="comment"
                                       placeholder=".....备注....."  type="text"  th:value="${good.comment}">
                            </div>
                        </div>




                        <div class="form-group col-md-10">
                            <button
                                    class="btn btn-primary ajax-post col-md-2"
                                    id="add-good-btn"
                                    target-form="add-form"
                                    type="button">确 定
                            </button>
                            <button
                                    class="btn btn-default col-md-2"
                                    onclick="history.back(-1);return false;"
                                    type="button">返 回
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </main>
        <!--End 页面主要内容-->
    </div>
</div>

<div th:insert="common/fragment::tail-script"></div>

<script type="text/javascript">
    $(function () {
        let goodunit = ["散装", "包", "公斤", "吨", "件", "套"]

        // 添加good按钮提交 - addgood.ajax
        $('#add-good-btn').on('click', function () {

            let id = $('#id').val()
            let goodname = $('#goodname').val();
            let spec = $('#spec').val();
            // let pk = $('#pk').val();
            let unit = $('#unit').val();
            unit = goodunit[unit]
            let comment = $('#comment').val();
            let status =$('input[name=goodstatus]:checked').val()
            // if(status === 'on'){
            //     status = 1
            // }else{
            //     status = -1
            // }

            if(goodname===''){
                confirmMsg('请填写商品名称')
                return
            }

            if(spec===''){
                confirmMsg('请填写商品规格')
                return
            }


            //生成data -- json

            let data = {
                id: id,
                name : goodname,
                spec:spec,
                unit: unit,
                status: status,
                comment: comment
            }
            //   let data = $('#icon-form').serialize()
            post_ajax('/good/editgood.ajax', data, '/good/goodlist.do');
            // console.log(data)

        });

        // 页面 禁用按钮 -- 提交后台 切换状态为禁用


    });
</script>
</body>
</html>